<template>
  <div>
    <el-divider></el-divider>
    <div style="font-size:20px;text-align:left">
      <i class="el-icon-document-checked">窗口挂号</i>
    </div>
    <el-divider></el-divider>
    <div style="text-align:left">
      <el-button type="primary" @click="addNewRegist">挂号</el-button>
      <el-button type="primary" @click="clearRegist">清空</el-button>
    </div>

    <el-descriptions title="基本信息"  :column="3" border style="margin-top:20px">
      <el-descriptions-item label="病历号">
        <el-input v-model="register.caseNumber" placeholder="请输入内容"></el-input>
      </el-descriptions-item>
      <el-descriptions-item label="姓名">
        <el-input v-model="register.realName" placeholder="请输入姓名"></el-input>
      </el-descriptions-item>
      <el-descriptions-item label="性别">
        <el-select v-model="register.gender" placeholder="请选择">
          <el-option v-for="item in registerGender"  :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="年龄">
<!--        <template>-->
          <el-input v-model="register.age" placeholder="请输入年龄" style="width:100px"></el-input>
          <el-select v-model="register.ageType" placeholder="请选择" style="width:80px">
            <el-option v-for="item in registerAgeType"  :key="item.value" :label="item.label" :value="item.value">

            </el-option>
          </el-select>
<!--        </template>-->
      </el-descriptions-item>
      <el-descriptions-item label="出生日期">
        <el-date-picker v-model="register.birthday" type="date"  placeholder="选择日期" value-format="YYYY-MM-DD">
        </el-date-picker>
      </el-descriptions-item>
      <el-descriptions-item label="身份证号">
        <el-input v-model="register.cardNumber" placeholder="请输入身份证号"></el-input>
      </el-descriptions-item>
      <el-descriptions-item label="家庭住址">
        <el-input v-model="register.homeAddress" placeholder="请输入家庭住址（可选）"></el-input>
      </el-descriptions-item>
    </el-descriptions>

    <el-descriptions title="挂号信息" :column="3" border style="margin-top:20px">
      <el-descriptions-item label="结算类别">
        <el-select v-model="register.settleIid" placeholder="请选择">
          <el-option v-for="item in registerSettle"  :key="item.id" :label="item.settleName" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="看诊日期">
        <el-date-picker disabled v-model="register.visitDdate" format="YYYY-MM-DD" type="date" placeholder="选择日期">
<!--        <el-date-picker disabled v-model="register.visit_date" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">-->
        </el-date-picker>
      </el-descriptions-item>
      <el-descriptions-item label="午别" >
        <el-select disabled v-model="register.noon" placeholder="请选择">
          <el-option v-for="item in registerNoon"  :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="挂号科室">
        <el-select v-model="register.deptmentId" placeholder="请选择">
          <el-option v-for="item in registerDept"  :key="item.id" :label="item.deptName" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="号别">
        <el-select v-model="register.registLevelId" placeholder="请选择" @change="registerLevelChange">
          <el-option v-for="item in registerLevel"  :key="item.id" :label="item.registName" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="看诊医生">
        <el-select v-model="register.employeeId" placeholder="请选择" @change="getAlreadyRegisterCount">
          <el-option label="请选择" value="0"></el-option>
          <el-option v-for="item in registerEmployee"  :key="item.id" :label="item.realname" :value="item.id">
          </el-option>
        </el-select>
      </el-descriptions-item>
      <el-descriptions-item label="初始号额" >
        <el-input disabled v-model="register.totalNumber" placeholder="初始号额"></el-input>
      </el-descriptions-item>
      <el-descriptions-item label="已用号额">
        <el-input disabled v-model="register.usedNumber" placeholder="已用号额"></el-input>
      </el-descriptions-item>
      <el-descriptions-item label="病历本">
        <el-switch v-model="register.isBook" active-color="#13ce66" inactive-color="#ff4949" @change="registerIsbookChange">
        </el-switch>
      </el-descriptions-item>
      <el-descriptions-item label="应收金额">
        <el-input disabled v-model="register.registMoney" placeholder="请输入金额"></el-input>
      </el-descriptions-item>
      <el-descriptions-item label="收费方式">
        <el-select v-model="register.registMethod" placeholder="请选择">
          <el-option v-for="item in registerMethod"  :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-descriptions-item>
    </el-descriptions>
  </div>
</template>
<script>

  import {ElMessage} from "element-plus";

  export default {

    data() {
      return {
        register:{
          id:'',
          caseNumber:'',//病历号
          realName:'',//姓名
          gender:'男',//性别
          cardNumber:'',//身份证
          birthday:'',//出生日期
          age:'',//年龄
          ageType:'年',//年龄类型
          homeAddress:'',//家庭住址
          visitDdate:'',//看诊日期
          noon:'上午',//午别
          deptmentId:'',//科室编号
          employeeId:'',//医生编号
          registLevelId:'',//挂号级别编号
          settleCategoryId:'1',//结算类别编号
          usedNumber:'0',//已用的号额
          isBook:false,//病历本
          registMethod:'医保卡',//收费方式
          registMoney:'',//收费金额
          visitState:'',//看诊状态
          totalNumber:0 //初始号额
        },
        registerGender:[
            {
              value:'男',
              label:'男'
            },
            {
              value:'女',
              label:'女'
            }
        ],
        registerAgeType:[
          {
            value:'年',
            label:'年'
          },
          {
            value:'天',
            label:'天'
          }
        ],
        registerMethod:[
          {
            value:'现金',
            label:'现金'
          },
          {
            value:'微信',
            label:'微信'
          },
          {
            value:'支付宝',
            label:'支付宝'
          },
          {
            value:'银行卡',
            label:'银行卡'
          },
          {
            value:'医保卡',
            label:'医保卡'
          }
        ],

        registerNoon:[
          {
            value:'上午',
            label:'上午'
          },
          {
            value:'下午',
            label:'下午'
          }
        ],
        //结算方式
        registerSettle:[],
        //部门-门诊
        registerDept:[],
        //挂号级别
        registerLevel:[],
        //门诊医生(员工)
        registerEmployee:[],
      }
    },
    methods:{


      //号别改变时事件对应的函数
      registerLevelChange:function ()
      {
          console.log(this.register.registLevelId)


        for(let i=0;i<this.registerLevel.length;i++){
          if(this.register.registLevelId==this.registerLevel[i].id){
            console.log(this.registerLevel[i].registFee)
            this.register.registMoney=this.registerLevel[i].registFee
           // alert(this.registerLevel[i].registQuota)
            this.register.totalNumber=this.registerLevel[i].registQuota
            //this.register.registLevelId=this.registerLevel[i].id
            //this.register.registMoney=this.this.registerLevel[i].registFee
            //退出循环
            break
          }

        }
        //显示对应的医生
        this.getRegisterEmployee()
      },

      //得到当前医生挂号的总数量
      getAlreadyRegisterCount:function (){
       // "employeeId":"7",
        //    "noon":"上午"
        if(this.registerIsFull())
        {
          return
        }

        this.$axios.post('http://localhost:8092/register/getuseregistercount',this.register).then(resp=>{
          this.register.usedNumber=resp.data.result

        }).catch(error=>{
          console.log(error)
        })

      },

      registerIsbookChange:function ()
      {
          if(this.register.isBook)
          {
            this.register.registMoney+=1
          }
          else {
            this.register.registMoney-=1
          }
      },

      //得到科室信息
      getRegisterDepart:function (){
        let deptType='门诊'
        let url=`http://localhost:8092/register/getdepartment/${deptType}`
        this.$axios.get(url).then(resp=>{
          this.registerDept=resp.data.result
          console.log(this.registerDept)

        }).catch(error=>{
          console.log(error)
        })
      },

      //得到科室信息
      getRegisterLevel:function (){
        this.$axios.get('http://localhost:8092/register/getregistlevel').then(resp=>{
          this.registerLevel=resp.data.result
          console.log(this.registerLevel)

        }).catch(error=>{
          console.log(error)
        })
      },
      //得到病历号
      getRegisterCaseNumber:function (){


        this.$axios.get('http://localhost:8092/register/getcasenumber').then(resp=>{
          this.register.caseNumber=resp.data.result
          console.log("+++++++++++++++++++"+this.register.cardNumber)
        }).catch(error=>{
          console.log(error)
        })
      },

      //得到门诊医生(员工)
      getRegisterEmployee:function (){

        let emp={
          "deptmentId":this.register.deptmentId,
          "registLevelId":this.register.registLevelId
        }
        this.$axios.post('http://localhost:8092/register/getemployee',emp).then(resp=>{
          this.registerEmployee=resp.data.result
          console.log("+++++++++++++++++++"+this.registerEmployee)
        }).catch(error=>{
          console.log(error)
        })
      },

      //得到结算方式
      getRegisterSettle:function (){
        this.$axios.get('http://localhost:8092/register/getsettlecategory').then(resp=>{
          this.registerSettle=resp.data.result
          console.log("+++++++++++++++++++"+this.registerEmployee)
        }).catch(error=>{
          console.log(error)
        })
      },
      //判断上下午
      getRegisterNoon:function ()
      {
         let date=new Date()
        if(date.getHours()>12)
        {
          this.register.noon="下午"
        }
        else {
          this.register.noon="上午"
        }
      },

      //挂号
      addNewRegist:function ()
      {
        if(this.registerIsFull())
        {
          return
        }
        this.register.isBook=this.register?'是':'否'
        this.register.visitState=1
        this.register.visitDate='2000-01-01'
        this.$axios.post('http://localhost:8092/register/insert',this.register).then(resp=>{
          ElMessage("挂号成功")
          //location.reload()
          this.register={}
          this.getRegisterCaseNumber()

        }).catch(error=>{
          console.log(error)
        })
      },

      //判断医生的号额是否挂满
      registerIsFull:function (){

        if(this.register.totalNumber==this.register.usedNumber)
        {
          ElMessage(
              {
                type:'warning',
                message:'该医生挂号已满'
              }
          )
          return true
        }
        return  false
      }
    },
    mounted() {
      //年月日 2024-12-17
      let date=new Date();
      this.register.visitDdate=date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()
      this.getRegisterCaseNumber()
      this.getRegisterDepart()
      this.getRegisterLevel()
      //this.getRegisterEmployee()

      this.getRegisterSettle()

      this.getRegisterNoon()
    }
  }
</script>